const connection = require("../db/sql");
const {delay} = require("../utils/delay");

/**
 * 获取数据库数据
 * @param sql sql语句
 * @returns {Promise<{res: *[], isErr: boolean}>}  返回结果和查询成功与否
 */
 async function getData(sql) {
     let isErr = false
     let result = [];

      connection.query(sql, function (err, res) {
         if (err) {
             isErr = true
             console.log(err)
             // throw err
         } else {
             result = [].concat(res, [])
         }
     })
     await delay(800)
     return {
         res: result,
         isErr
     }
 }

 module.exports = {
    getData
 }
